//
//  DingDanMainViewController.m
//  ShangChengMoBan
//
//  Created by 军 on 16/8/29.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "DingDanMainViewController.h"
#import "DingDanRowTableViewCell.h"
#import "ContentViewController.h"
#import "FaBiaoViewController.h"
#import "BaseTableView.h"
#import "DD_Allmodel.h"
#import "DD_shopModel.h"
@interface DingDanMainViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>

@end

@implementation DingDanMainViewController
{
    UIView * _bigView;
    UIView * _tanKuang,* _tanKuang2,*_view,* _viewNo;
    UITextField * _inputTextField;
    UITextView * _textView;
    UIView * _viewFang;
    int _page;
    UIView * headerView;
    UIView * footView;
    UIView * view2;
    UIButton * button1,* button2,* button3,* button4;
    ContentViewController * content;//详情页
    RWScrollView *_table;
    NSMutableArray *_Allarray;
    NSMutableArray * _wuLiu; //商品物流详情
     NSMutableArray * _prizeArr;
    NSInteger _biaoJi;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _page = 1;
    _prizeArr = [[NSMutableArray alloc]init];
     _table = [[RWScrollView alloc]initWithFrame:CGRectMake(0, 5, KScreenWidth, KScreenHeight-104) style:UITableViewStyleGrouped];
     _table.separatorStyle = UITableViewCellSelectionStyleNone;
    [_table registerClass:[DingDanRowTableViewCell class] forCellReuseIdentifier:@"cell"];
    _table.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.92 alpha:1.00];
    [_table addHeaderWithTarget:self action:@selector(headRefresh)];
    [_table addFooterWithTarget:self action:@selector(footerRefresh)];
    _table.delegate = self;
    _table.dataSource = self;
    [self.view addSubview:_table];
    [self noShopView];
     [self drawYuEView];
    [self drawYuEView2];
    [self zhiFuFangShi];
     [TCUtils showLoadingWithView:[UIApplication sharedApplication].keyWindow];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(zhuangTai) name:@"检测状态" object:nil];
    }
-(void)requestDatasWith{
    [_table headerBeginRefreshing];
}
-(void)headRefresh{
    _page = 1;
    [self qingQiu:1];
}
-(void)footerRefresh{
    _page ++;
    [self qingQiu:0];
}
-(void)qingQiu:(int)first{
    switch (_num) {
        case 1:
            [self requestData:nil :first];
            break;
        case 2:
            [self requestData:@0 :first];
            break;
        case 3:
            [self requestData:@1 :first];
            break;
        case 4:
            [self requestData:@2 :first];
            break;
        default:
             [self requestData:@4 :first];
            break;
    }

}
-(void)requestData:(NSNumber *)shippingStatus :(int)page{
  
    NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
    [dic setObject:@"10" forKey:@"pageSize"];
    [dic setObject:[NSString stringWithFormat:@"%d",_page] forKey:@"pageNum"];
    if (shippingStatus != nil) {
        [dic setObject:shippingStatus forKey:@"orderStatus"];
    }
     [NetWorking NEWjieKouQingQiu:DD_queryOrder ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
          [TCUtils hiddonLoadingWithView:[UIApplication sharedApplication].keyWindow ];
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                if(page == 1  ){
                    _Allarray = [[NSMutableArray alloc]init];
                }
                NSArray * arr = dic[Response];
                [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    DD_Allmodel * allModel = [DD_Allmodel objectFromDictionary:obj];
                    [_Allarray addObject:allModel];
                }];
                 [_table reloadData];//刷新tableView
                if (arr.count == 0 && _page == 1) {
                    _viewNo.hidden = NO;
                }else{
                    _viewNo.hidden = YES;
                }
            }
        }
    }];
    [_table headerEndRefreshing];
    [_table footerEndRefreshing];
}
-(void)noShopView{
    _viewNo = [[[NSBundle mainBundle]loadNibNamed:@"NoShop" owner:self options:nil] lastObject];
    _viewNo .hidden = YES;
    _viewNo.frame = CGRectMake(0, 100, KScreenWidth, 127);
    [_table addSubview:_viewNo];
}
#pragma mark 组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
       return _Allarray.count;
}
#pragma mark 行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    DD_Allmodel * allModel =  _Allarray[section];
    return allModel.OrderGoods.count;
}
//#pragma mark 每组头部试图
//-(UIView * )tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//     DD_Allmodel * allModel =  _Allarray[section];
//    headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 50)];
//    headerView.backgroundColor = [ UIColor whiteColor];
//    UILabel * title2 = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth-150, 10, 140, 30)];
//    title2.font = [UIFont systemFontOfSize:14];
//    title2.textColor = [UIColor redColor];
//    title2.textAlignment = NSTextAlignmentRight;
//    [headerView addSubview:title2];
//    int num1 = [allModel.payStatus intValue];
//    int num2 = [allModel.shippingStatus intValue];
//    int num3 = [allModel.orderStatus intValue];
//    if (num3 == 2) {
//         title2.text=@"订单已取消";
//    }else{
//    if (num1 == 0) {
//         title2.text=@"等待买家付款";
//    }else if(num1 ==2)
//    {
//        switch (num2) {
//            case 0:
//            {
//                 title2.text=@"买家已付款";
//            }
//                break;
//            case 1:
//            {
//               title2.text=@"卖家已发货";
//            }
//                break;
//            case 2:
//            {
//                 title2.text=@"交易成功";
//            }
//                break;
//            default:
//            {
//              
//            }
//                break;
//        }
//
//    }
//}
//        return headerView;
//}
#pragma mark 每组底部视图
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    DD_Allmodel * allModel =  _Allarray[section];
    int num1 = [allModel.payStatus intValue];
    int num2 = [allModel.shippingStatus intValue];
    int num3 = [allModel.orderStatus intValue];
    int num4 = [allModel.commentStatus intValue];
    if (num3 == 2) {
         [self view1];
        [button1 removeFromSuperview];
        [button2 removeFromSuperview];
        [button3 setTitle:@"删除订单" forState:UIControlStateNormal];
        [button3 addTarget:self action:@selector(remove:) forControlEvents:UIControlEventTouchUpInside];
    }else{
    if (num1 == 0) {
        [self view1];
        [button1 setTitle:@"联系卖家" forState:UIControlStateNormal];
        [button2 setTitle:@"取消订单" forState:UIControlStateNormal];
        [button3 setTitle:@"付款" forState:UIControlStateNormal];
         button1.tag=section;
         button2.tag=section;
         button3.tag=section;
        [button3 addTarget:self action:@selector(fuKuan:) forControlEvents:UIControlEventTouchUpInside];
        [button2 addTarget:self action:@selector(quXiao:) forControlEvents:UIControlEventTouchUpInside];
        [button1 addTarget:self action:@selector(lianXi:) forControlEvents:UIControlEventTouchUpInside];
    }else if(num1 ==2){
     switch (num2) {
        case 0://待发货
         {
          [self view2];
         }
           
            break;
        case 1://待收货
         {
             [self view1];
             [button2 addTarget:self action:@selector(tuiKuan:) forControlEvents:UIControlEventTouchUpInside];
             [button1 addTarget:self action:@selector(wuLui:) forControlEvents:UIControlEventTouchUpInside];
             [button3 addTarget:self action:@selector(queRenShouHuo:) forControlEvents:UIControlEventTouchUpInside];
             button1.tag=section;
             button2.tag=section;
             button3.tag=section;
         }
            break;
         case 2://待评论
         {
             
             [self view1];
             [button2 setTitle:@"删除订单" forState:UIControlStateNormal];
             if (num4 == 0) {
                 [button3 setTitle:@"评论" forState:UIControlStateNormal];
                 [button3 addTarget:self action:@selector(pingLun:) forControlEvents:UIControlEventTouchUpInside];
             }else{
             [button3 setTitle:@"已完成" forState:UIControlStateNormal];
             }
             [button2 addTarget:self action:@selector(remove:) forControlEvents:UIControlEventTouchUpInside];
             [button1 addTarget:self action:@selector(wuLui:) forControlEvents:UIControlEventTouchUpInside];
            
             button1.tag=section;
             button2.tag=section;
             button3.tag=section;
         }
             break;
        default:
             break;
    }
    }
    }
    if (num1 == 2 && num2==0) {
        return view2;
    }
    return footView;
}
#pragma mark 取消订单
-(void)quXiao:(UIButton *)button{
    int tag =(int)button.tag+1000;
       [TCUtils showAlertViewWithTitle:@"提醒" message:@"你确定要取消订单吗?" delegate:self cancel:@"取消" other:@"确定" tag:tag];
  }
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex ==1) {
    if (alertView.tag/1000 == 1) {
        DD_Allmodel * allModel = _Allarray[alertView.tag%1000];
        NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
        [dic setObject:allModel.orderId forKey:@"orderId"];//订单ID
        [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
        [NetWorking NEWjieKouQingQiu:DD_cancelOrder ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
            if (!error) {
                if ([dic[Code] intValue] == 200) {
                    [[iToast makeText:@"  成功取消订单!  "] show];
                    [_table headerBeginRefreshing];
                }
            }
        }];
    }else if (alertView.tag/1000 == 2){
        DD_Allmodel * allModel = _Allarray[alertView.tag%1000];
        NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
        [dic setObject:allModel.orderId forKey:@"orderId"];//订单ID
        [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
        [NetWorking NEWjieKouQingQiu:DD_deleteOrderInfo ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
            if (!error) {
                if ([dic[Code] intValue] == 200) {
                    [[iToast makeText:@"  成功删除订单!  "] show];
                    [_table headerBeginRefreshing];
                }
            }
        }];
    
    }
    }
}
-(void)drawYuEView{
    _tanKuang = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    _tanKuang.alpha = 0.0;
    _tanKuang.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    [[UIApplication sharedApplication].keyWindow addSubview:_tanKuang];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [_tanKuang addGestureRecognizer:tap];
    
    _view = [[UIView alloc]initWithFrame:CGRectMake(25, KScreenHeight/2-75, KScreenWidth-50, 152)];
    _view.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.93 alpha:1.00];
    [_tanKuang addSubview:_view];
    UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-50, 35)];
    lable.backgroundColor = [UIColor redColor];
    lable.textColor = [UIColor whiteColor];
    lable.text = @"验证登录密码!";
    lable.textAlignment = NSTextAlignmentCenter;
    lable.font = [UIFont systemFontOfSize:13];
    [_view addSubview:lable];
    _inputTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, lable.bottom, KScreenWidth-50, 65)];
    _inputTextField.textAlignment = NSTextAlignmentCenter;
    _inputTextField.font = [UIFont systemFontOfSize:13];
    _inputTextField.backgroundColor = [UIColor whiteColor];
    [_view addSubview:_inputTextField];
    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, _inputTextField.bottom+1, KScreenWidth-50, 50)];
    button.backgroundColor = [UIColor whiteColor];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button addTarget:self action:@selector(queMiMaEnd) forControlEvents:UIControlEventTouchUpInside];
    [_view addSubview:button];
}
-(void)tap:(UITapGestureRecognizer *)tap{
    _tanKuang.alpha = 0.0;
    _tanKuang.hidden = YES;
    _tanKuang2.alpha = 0.0;
//    _bigView.hidden = YES;
//     _bigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
  }
#pragma mark 付款
-(void)fuKuan:(UIButton *)button{
    _biaoJi= button.tag;
     _bigView.hidden = NO;
    [UIView animateWithDuration:0.5 animations:^{
        _viewFang.yv = KScreenHeight-130;
         _bigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    }];
}
-(void)zhiFuFangShi{
    _bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
     _bigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
    _bigView.hidden = YES;
     [[UIApplication sharedApplication].keyWindow addSubview:_bigView];
//    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
//    [_bigView addGestureRecognizer:tap];
     _viewFang = [[UIView alloc]initWithFrame:CGRectMake(0, KScreenHeight, KScreenWidth, 130)];
    _viewFang.backgroundColor = [UIColor whiteColor];
    NSArray *image = @[@"支付宝",@"微信支付",@"余额"];
    NSArray *title = @[@"支付宝",@"微信",@"fpl积分"];
    int width = 35*_kscW;
    int height = width;
    int zong = KScreenWidth/3;
    int zuo = (zong-width)/2;
    for (int i = 0; i<3; i++) {
        UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(zong*i+zuo, 20, width, height)];
        [button addTarget:self action:@selector(zhiFu:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i;
        [button setBackgroundImage:[UIImage imageNamed:image[i]] forState:UIControlStateNormal];
        [_viewFang addSubview:button];
        UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(zong*i, button.bottom+5, zong, 20)];
        lable.text = title[i];
        lable.font = [UIFont systemFontOfSize:14];
        lable.textAlignment = NSTextAlignmentCenter;
        [_viewFang addSubview:lable];
    }
    UIButton * que = [[UIButton alloc]initWithFrame:CGRectMake(0, 95, KScreenWidth, 35)];
    que.backgroundColor =[UIColor redColor];
    [que setTitle:@"取消" forState:UIControlStateNormal];
    que.titleLabel.font = [UIFont systemFontOfSize:15];
    [que setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [que addTarget:self action:@selector(xiaoShi) forControlEvents:UIControlEventTouchUpInside];
    [_viewFang addSubview:que];
    [[UIApplication sharedApplication].keyWindow addSubview:_viewFang];
}
-(void)xiaoShi{
    _bigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
    _bigView.hidden = YES;
    [UIView animateWithDuration:0.5 animations:^{
        _viewFang.yv = KScreenHeight;
     }];
    
}
-(void)zhiFu:(UIButton *)button{
    [UIView animateWithDuration:0.5 animations:^{
        _viewFang.yv = KScreenHeight;
    }];
    _bigView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.0];
    _bigView.hidden = YES;
    if (button.tag == 0) {
        
    }else if (button.tag == 1){
    
    }else{
        [UIView animateWithDuration:0.5 animations:^{
            _tanKuang.alpha = 1.0;
            _tanKuang.hidden = NO;
            [_inputTextField becomeFirstResponder];
        }];
    }
}
-(void)queMiMaEnd{
    _tanKuang.hidden = YES;
    _tanKuang.alpha = 0.0;
    //支付接口
    DD_Allmodel * allModel = _Allarray[_biaoJi];
    NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
    [dic setObject:allModel.orderId forKey:@"orderId"];//订单ID
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
     [dic setObject:_inputTextField.text forKey:@"password"];
    _inputTextField.text = @"";
    [NetWorking NEWjieKouQingQiu:DD_insertOne ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                [[iToast makeText:@"  支付成功!  "] show];
                  [_table headerBeginRefreshing];
            }
        }
    }];
}

#pragma mark 联系卖家
-(void)lianXi:(UIButton *)button{
    NSLog(@"联系卖家");
}
#pragma mark 删除订单
-(void)remove:(UIButton *)button{
    int tag =(int)button.tag+2000;
    [TCUtils showAlertViewWithTitle:@"提醒" message:@"你确定要删除订单吗?" delegate:self cancel:@"取消" other:@"确定" tag:tag];
 }
#pragma mark 查看物流
-(void)wuLui:(UIButton *)button{
    DD_Allmodel * allModel = _Allarray[button.tag];
    NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
    [dic setObject:allModel.orderId forKey:@"orderId"];//订单ID
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
    [NetWorking NEWjieKouQingQiu:@"商品物流" ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                [_wuLiu addObjectsFromArray:dic[Response]];
            }
        }
    }];
    NSLog(@"进入物流");
}
#pragma mark 确认收货
-(void)queRenShouHuo:(UIButton *)button{
    NSLog(@"%li",(long)button.tag);
    DD_Allmodel * allModel = _Allarray[button.tag];
    NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
    [dic setObject:allModel.orderId forKey:@"orderId"];//订单ID
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
    [NetWorking NEWjieKouQingQiu:DD_receive ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                [_table headerBeginRefreshing];
             }
        }
    }];
}
#pragma mark 评论
-(void)pingLun:(UIButton *)button{
     DD_Allmodel * allModel = _Allarray[button.tag];
    FaBiaoViewController * pingLun  = [[FaBiaoViewController alloc]init];
    pingLun.orderID =allModel.orderId;
    pingLun.timp = 1;
    [self.navigationController pushViewController:pingLun animated:YES];
}
#pragma mark 退款
-(void)tuiKuan:(UIButton *)button{
    _biaoJi= button.tag;
    [_textView becomeFirstResponder];
    [UIView animateWithDuration:0.5 animations:^{
        _tanKuang2.alpha = 1.0;
    }];
}
-(void)drawYuEView2{
    _tanKuang2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    _tanKuang2.alpha = 0.0;
    _tanKuang2.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    [[UIApplication sharedApplication].keyWindow addSubview:_tanKuang2];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [_tanKuang2 addGestureRecognizer:tap];
    
    _view = [[UIView alloc]initWithFrame:CGRectMake(25, KScreenHeight/2-75, KScreenWidth-50, 152)];
    _view.backgroundColor = [UIColor whiteColor];
    [_tanKuang2 addSubview:_view];
    UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth-50, 35)];
    lable.backgroundColor = [UIColor redColor];
    lable.textColor = [UIColor whiteColor];
    lable.text = @"请输入申请理由!";
    lable.textAlignment = NSTextAlignmentCenter;
    lable.font = [UIFont systemFontOfSize:13];
    [_view addSubview:lable];
    _textView = [[UITextView alloc]initWithFrame:CGRectMake(10, lable.bottom, KScreenWidth-70, 85)];
    _textView.font = [UIFont systemFontOfSize:13];
    _textView.backgroundColor = [UIColor whiteColor];
    [_view addSubview:_textView];
    UIView * xi = [[UIView alloc]initWithFrame:CGRectMake(0, _textView.bottom, KScreenWidth, 1)];
    xi.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.87 alpha:1.00];
    [_view addSubview:xi];
    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, xi.bottom, KScreenWidth-50, 30)];
    button.backgroundColor = [UIColor whiteColor];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button addTarget:self action:@selector(queMiMaEnd2) forControlEvents:UIControlEventTouchUpInside];
    [_view addSubview:button];
}
-(void)queMiMaEnd2{
    [UIView animateWithDuration:0.5 animations:^{
        _tanKuang2.alpha = 0.0;
        }];
    DD_Allmodel * allModel = _Allarray[_biaoJi];
    NSMutableDictionary * dic =[ [NSMutableDictionary alloc]init];
    [dic setObject:allModel.orderId forKey:@"orderId"];//订单ID
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
    [dic setObject:_textView.text forKey:@"postscript"];//退款留言
    [dic setObject:@"1" forKey:@"backPay"];//退款方式
    [dic setObject:@"1" forKey:@"backType"];//退款类型
    [NetWorking NEWjieKouQingQiu:DD_refund ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        NSLog(@"%@",dic[Msg]);
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                [[iToast makeText:@"  申请成功!  "] show];
                [_table headerBeginRefreshing];
            }
        }
    }];
}
#pragma mark 底部按钮view
-(UIView *)view1{
    footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 46)];
    footView.backgroundColor = [UIColor whiteColor];
    UIView * viewXian = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 1)];
    viewXian.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.87 alpha:1.00];
    [footView addSubview:viewXian];
    button1 = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth/4, 8, KScreenWidth/4-10, 24)];
    [button1 setTitle:@"查看物流" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button1.layer.cornerRadius=3;
    button1.layer.borderColor = [UIColor lightGrayColor].CGColor;
    button1.layer.borderWidth=1;
    button1.titleLabel.font = [UIFont systemFontOfSize:13];
    [footView addSubview:button1];
    button2 = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth/4*2, 8, KScreenWidth/4-10, 24)];
    [button2 setTitle:@"申请退款" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize:13];
    button2.layer.cornerRadius=3;
    button2.layer.borderColor = [UIColor lightGrayColor].CGColor;
    button2.layer.borderWidth=1;
    [footView addSubview:button2];
    button3 = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth/4*3, 8, KScreenWidth/4-10, 24)];
    [button3 setTitle:@"确认收货" forState:UIControlStateNormal];
    button3.titleLabel.font = [UIFont systemFontOfSize:13];
    button3.layer.cornerRadius=3;
    button3.layer.borderColor = [UIColor redColor].CGColor;
    [button3 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    button3.layer.borderWidth=1;
    [footView addSubview:button3];
    UIView * viewXian2 = [[UIView alloc]initWithFrame:CGRectMake(0, button3.bottom+10, KScreenWidth, 6)];
    viewXian2.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.87 alpha:1.00];
    [footView addSubview:viewXian2];
    return footView;
}
#pragma mark 底部等待商家发货
-(UIView *)view2{
    view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 46)];
    view2.backgroundColor = [UIColor whiteColor];
    UIView * viewXian = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 1)];
    viewXian.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.87 alpha:1.00];
    [view2 addSubview:viewXian];
    UILabel * lable =[[UILabel alloc]initWithFrame:CGRectMake(0, 10, KScreenWidth-8, 25)];
    lable.text = @"请等待商家发货";
    lable.textColor = [UIColor redColor];
    lable.textAlignment = NSTextAlignmentRight;
    lable.font = [UIFont systemFontOfSize:13];
    [view2 addSubview:lable];
    UIView * viewXian2 = [[UIView alloc]initWithFrame:CGRectMake(0, lable.bottom+8, KScreenWidth, 6)];
    viewXian2.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.87 alpha:1.00];
    [view2 addSubview:viewXian2];
    button4 = [[UIButton alloc]initWithFrame:CGRectMake(10, 8, KScreenWidth/4-10, 24)];
    [button4 setTitle:@"申请退款" forState:UIControlStateNormal];
    button4.titleLabel.font = [UIFont systemFontOfSize:13];
    button4.layer.cornerRadius=3;
    button4.layer.borderColor = [UIColor redColor].CGColor;
    [button4 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button4 addTarget:self action:@selector(tuiKuan:) forControlEvents:UIControlEventTouchUpInside];
    button4.layer.borderWidth=1;
    [view2 addSubview:button4];
    return view2;
}
#pragma mark 头部高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}
#pragma mark 底部高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 46;
}
#pragma mark 行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 123;
}
#pragma mark 绘制cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DD_Allmodel * allModel = _Allarray[indexPath.section];
    DD_shopModel * shopModel = allModel.OrderGoods[indexPath.row];
    DingDanRowTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    NSMutableAttributedString *  attribtStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%.2f",[shopModel.marketPrice floatValue]+[shopModel.attr_price floatValue]] ];
    [attribtStr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0,attribtStr.length)];
    cell.zheKou.attributedText = attribtStr;  //商品原价
    cell.title.text = shopModel.goodsName;    //商品名称
    [cell.image sd_setImageWithURL:[NSURL URLWithString:shopModel.goodsImg]];  //商品图片
    cell.prize.text =  [NSString stringWithFormat:@"¥%.2f", [shopModel.goodsPrice floatValue]+[shopModel.attr_price floatValue]];   //商品售价
    cell.num.text = [NSString stringWithFormat:@"X%@",shopModel.goodsNumber];//商品数量
    NSString * a = shopModel.goodsAttr;
    cell.size.text = a;
    if (![a isEqualToString:@""]) {
        cell.size.text = [a substringWithRange:NSMakeRange(0, a.length-1)];   //商品属性
    }
    return cell;
}
#pragma mark 点击cell进入详情页
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    content = [[ContentViewController alloc]init];
    content.allModel = _Allarray[indexPath.section];
    [self.navigationController pushViewController:content animated:YES];
 }
-(void)zhuangTai{
    [_table headerBeginRefreshing];
}
@end
